<?php
class Main_model extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    /*function get_last_ten_entries()
    {
        $query = $this->db->get('entries', 10);
        return $query->result();
    }*/

    function add_account($data)
    {
        $this->db->insert('accounts', $data);
    }
    
    function account_available($data)
    {
    	$query = $this->db->get('accounts');
    	foreach ($query->result() as $row)
    	{
    		//is the requested username already taken?
    		if($row->name == $data['name']){
    			return false;
    		}
    	}
    	return true;
    }
    
    function account_compare_login($data)
    {
    	$query = $this->db->query("SELECT * FROM accounts WHERE name = '".$data['name'] ."' AND pass = '".$data['pass']."'");
    	$name = "";
    	$pass = "";
    	foreach ($query->result() as $row)
    	{
    		$name = $row->name;
    		$pass = $row->pass;
    	}
    	if($name == $data['name'] && $pass == $data['pass'] && $pass!=""){
    		return true;
    	}
    	return false;
    }
    
    function update_account($name, $data)
    {
    	$this->db->where('name', $name);
    	$this->db->update('accounts', $data);
    	
    }
    
    function get_style($name)
    {
    	$query = $this->db->get_where('accounts', array('name' => $name));
    	$style = "main.css";
    	foreach ($query->result() as $row)
    	{
    		$style = $row->style;
    	}
    	return $style;
    }
    
    function get_bg($name)
    {
    	$query = $this->db->get_where('accounts', array('name' => $name));
    	$bg = "orange.jpg";
    	foreach ($query->result() as $row)
    	{
    		$bg = $row->background;
    	}
    	return $bg;
    }
    
    function get_recommendations($name)
    {
    	$query = $this->db->get_where('accounts', array('name' => $name));
    	$r = "";
    	foreach ($query->result() as $row)
    	{
    		$r = $row->recommendations;
    	}
    	return $r;
    }

    /*function update_entry()
    {
        $this->title   = $_POST['title'];
        $this->content = $_POST['content'];
        $this->date    = time();

        $this->db->update('entries', $this, array('id' => $_POST['id']));
    }*/

}
?>